<!DOCTYPE html>
<html lang="en" class="loginHtml">
<head>
  <meta charset="UTF-8">
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=building-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="/css/public.css" media="all" />
	<title>华迪系统后台登录界面</title>
</head>
<body class="loginBody">
		<form action="" method="post" class="layui-form">
			<div class="login_face"><img src="/images/default.png" class="userAvatar"></div>
			<div class="layui-form-item input-item">
				<label for="account">账号</label>
				<input type="text" placeholder="请输入用户名" name="account" id="account"  class="layui-input" lay-verify="required"/>
			</div>
			<div class="layui-form-item input-item">
				<label for="password">密码</label>
				<input type="password" placeholder="请输入密码" name="password" id="password" class="layui-input" lay-verify="required" />
			</div>
			<div class="layui-form-item input-item" id="imgCode">
				<label for="code">验证码</label>
				<input type="text" name="code" placeholder="请输入验证码" id="code" class="layui-input">
				<img id="imgObj" src="/console/code" alt="验证码图片" onclick="changeImg();" style="height:40px;width:115px;cursor: pointer;">
			</div>
			<div class="layui-form-item">
				<button class="layui-btn layui-block" lay-filter="login" lay-submit>登录</button>
			</div>
		</form><!-- form -->
</body>
</html>
<script type="text/javascript" src="/layui/layui.js"></script>
<script>
    function changeImg() {
        var imgSrc = $("#imgObj");
        var src = imgSrc.attr("src");
        imgSrc.attr("src", chgUrl(src));
    }
    //时间戳
    //为了使每次生成图片不一致，即不让浏览器读缓存，所以需要加上时间戳
    function chgUrl(url) {
        var timestamp = (new Date()).valueOf();
        url = url.substring(0, 18);
        if ((url.indexOf("&") >= 0)) {
            url = url + "×tamp=" + timestamp;
        } else {
            url = url + "?timestamp=" + timestamp;
        }
        return url;
    }
    layui.use(['form','layer','jquery'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer
        $ = layui.jquery;

        //登录按钮
        form.on("submit(login)",function(data){
            var x=$(this);
            x.text("登录中...").attr("disabled","disabled").addClass("layui-disabled");
            $.ajax({
                type: "POST",
                url: "/console/login",  //后台程序地址
                data:data.field,
                success: function(data){           //后台程序返回的标签，比如我喜欢使用1和0 表示成功或者失败
                    if (data.status==200){   //如果成功了
                        window.location.href =data.msg;
                    }else if(data.status==500){
                        x.text("登录").removeAttr("disabled").removeClass("layui-disabled");
                        layer.msg(data.msg);
                    }
                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        })

        //表单输入效果
        $(".loginBody .input-item").click(function(e){
            e.stopPropagation();
            $(this).addClass("layui-input-focus").find(".layui-input").focus();
        })
        $(".loginBody .layui-form-item .layui-input").focus(function(){
            $(this).parent().addClass("layui-input-focus");
        })
        $(".loginBody .layui-form-item .layui-input").blur(function(){
            $(this).parent().removeClass("layui-input-focus");
            if($(this).val() != ''){
                $(this).parent().addClass("layui-input-active");
            }else{
                $(this).parent().removeClass("layui-input-active");
            }
        })
    })
</script>
